package loveqq.niceexcel.read.builder;

import cn.hutool.core.collection.CollUtil;
import loveqq.niceexcel.converter.Converter;
import loveqq.niceexcel.read.ReadSheet;
import loveqq.niceexcel.read.handler.ReadHandler;

import java.util.ArrayList;

/**
 * @author zhongjh@tsintergy.com
 * @date 2022-08-23
 */
public class ReadSheetBuilder<T> {

    private final ReadSheet<T> readSheet;

    public ReadSheetBuilder(Class<T> headClass) {
        this.readSheet = new ReadSheet<>(headClass);
        this.readSheet.setReadHandlerList(new ArrayList<>());
        this.readSheet.setConverterList(new ArrayList<>());
    }

    public ReadSheet<T> build() {
        return this.readSheet;
    }

    public ReadSheetBuilder<T> sheetIndex(Integer... sheetIndex) {
        this.readSheet.setSheetIndexes(CollUtil.newLinkedHashSet(sheetIndex));
        return this;
    }

    public ReadSheetBuilder<T> sheetName(String... sheetName) {
        this.readSheet.setSheetNames(CollUtil.newLinkedHashSet(sheetName));
        return this;
    }

    public ReadSheetBuilder<T> sheetAll() {
        this.readSheet.setAllSheet(true);
        return this;
    }

    public ReadSheetBuilder<T> addReadHandler(ReadHandler readHandler) {
        this.readSheet.getReadHandlerList().add(readHandler);
        return this;
    }

    public ReadSheetBuilder<T> addConverter(Converter<?> converter) {
        this.readSheet.getConverterList().add(converter);
        return this;
    }

}
